package com.be.beadmin.basicData.entity;

import com.be.beadmin.common.entity.BaseEntity;
import com.fasterxml.jackson.annotation.JsonBackReference;
import lombok.Getter;
import lombok.Setter;

import javax.persistence.*;
import java.util.HashSet;
import java.util.Set;

/**
 * @author chenwei
 * @date 2/24/2023 3:45 PM
 * 角色表
 */
@Entity
@Table(name="SYS_ROLE")
@Getter
@Setter
public class Role  extends BaseEntity {
    /**
     * 角色名称
     */
    @Column(name = "NAME",columnDefinition = "VARCHAR(30) COMMENT '角色名称' ")
    private String name;

    /**
     * 角色编码
     */
    @Column(name = "CODE",columnDefinition = "VARCHAR(30) COMMENT '角色编码，必须以ROLE_开头' ")
    private String code;

    /**
     * 角色描述
     */
    @Column(name = "DESCRIPTION",columnDefinition = "VARCHAR(200) COMMENT '角色用途说明' ")
    private String description;

    @JsonBackReference
    @ManyToMany(mappedBy = "roles"  // 放弃维权,由用户去管理
    )
    private Set<User> users = new HashSet<>();



    @JsonBackReference
    @ManyToMany(
//            targetEntity = Menu.class, cascade = CascadeType.ALL,
            fetch= FetchType.LAZY)
    @JoinTable(name = "SYS_ROLE_MENU",joinColumns = @JoinColumn(name = "ROLE_ID"),inverseJoinColumns = @JoinColumn(name = "MENU_ID"))
    private Set<Menu> menus = new HashSet<>();


    //是否是系统角色
    @Column(name = "IS_SYSTEM")
    private Boolean system = false;
}
